<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$pSel = '<select id="vms-select-package">';
$packages = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}vms_packages ORDER BY keyname ASC");
foreach($packages as $k=>$v){
    echo $v['id'].' '.$this->getContentLang('package_title', $v['id']).'<br />';
    if(get('package')==$v['id']) $selected = 'selected="selected"';
    else $selected = '';
    $pSel .= '<option value="'.$v['id'].'" '.$selected.'>'.$this->getContentLang('package_title', $v['id']).'</option>';
}
$pSel .= '</select>';


if(count($packages)>0) echo $pSel;
else{
    echo '<p>No packages defined yet</p>';
}

$packageid = (int) get('package');

$pData = $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}vms_packages WHERE id = '{$packageid}'");

if(is_array($pData) && count($pData)>0){
    // valid package selected

    if(Antz_IntelliForm::submitted('access-permissions')){
        $ag = $_POST['groups'];

    }



    $ag = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}vms_packages_to_groups WHERE package_id = '{$packageid}'");
    $authGroups = array();
    foreach($ag as $k=>$v){
        $authGroups[] = $v;
    }

    $groups = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}iusers_groups ORDER BY keyname ASC");
    $groupOpts = array();
    foreach($groups as $k=>$v){
        $groupOpts[$v['keyname']] = $v['title'];
    }





    $formFields = array(
        array(
            'type' => 'select',
            'name' => 'groups[]',
            'multiple' => true,
            'size' => 6,
            'value' => $authGroups,
            'options' => $groupOpts,
            'label' => 'Authorized Groups'
        ),
        array(
            'type' => 'submit',
            'name' => 'submitBtn',
            'value' => 'Update',
            'label' => '&nbsp;'
        )
    );

    echo JFX::makeRapidForm($formFields, 'Access Settings', 'access-permissions');





}






































